import request from '@/js/request'
import {CONTENT_TYPE_FORM_URLENCODED} from '@/js/api/requestHeaderUtils'

const BASE_URL = '/model/config/labels'

export function getModelChildrenLabelData(parentId) {
  return request.get(BASE_URL, {params: {parentId: parentId}})
}

export function getModelRootTreeData() {
  return getModelChildrenLabelData('-1')
}

export function saveAndUpdateModelLabel(label, isAdd) {
  if (isAdd){
    return request.post(BASE_URL, label)
  } else {
    return request.put(BASE_URL, label)
  }
}

export function deleteLabel(labelId) {
  return request.delete(BASE_URL + '/' + labelId)
}

export function getLabel(labelId) {
  return request.get(BASE_URL + '/' + labelId)
}

export function loadModelLabels() {
  return request.get(BASE_URL + '/model/loadModelLabels')
}

export function filterLabels(condition) {
  return request.post(BASE_URL + '/filter',
    'condition=' + encodeURIComponent(condition),
    {
      headers: {'Content-Type': CONTENT_TYPE_FORM_URLENCODED}
    }
  )
}
